package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.entity.ArtistClassDetailEntity;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/27.
 */
public class ArtistClassDetailAdapter extends BaseAdapter {
    private Context mContext;
    private List<ArtistClassDetailEntity.ArtistEntity> datas;

    public ArtistClassDetailAdapter(Context context, List<ArtistClassDetailEntity.ArtistEntity> lists) {
        datas = lists;
        mContext = context;
    }

    @Override
    public int getCount() {
        return datas.size() > 0 && datas != null ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.artist_class_detail_listview_item, null);
            holder = new ViewHolder();
            holder.artistName = (TextView) convertView.findViewById(R.id.artist_class_detail_item_textView);
            holder.artistPic = (ImageView) convertView.findViewById(R.id.artist_class_detail_item_pic);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ArtistClassDetailEntity.ArtistEntity artistEntity = (ArtistClassDetailEntity.ArtistEntity) getItem(position);

        if (artistEntity != null) {
            holder.artistName.setText(artistEntity.getName());
            Picasso.with(mContext).load(artistEntity.getAvatar_middle()).placeholder(R.mipmap.musiclogo).into(holder.artistPic);
        }
        return convertView;
    }

    public class ViewHolder {
        private TextView artistName;
        private ImageView artistPic;

    }

}
